home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The PC-SIG Library 10
/
The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso
/
PC_SIGCD
/
05
/
6
/
DISK0564.ZIP
/
SOURCE.ARC
/
B.ARC
/
FSEARCH.C
< prev
next >
Wrap
C/C++ Source or Header
|
1986-04-09
|
2KB
|
85 lines
/* DOS-specific routines to search for files matching a file specification */
/* ? and * wildcards are supported */
/* for Manx Aztec C86, v. 3.2 */
/* by Jon Dart, 03-Mar-86 */
/* modified 09-Apr-86 */
/* Note: DS = ES (small data model) is assumed */
static char *buf;
struct regstruc {
unsigned int ax,bx,cx,dx,si,di;
} inregs,outregs,temp;
extern unsigned int doscall();
extern char *cpycnt();
extern char *malloc();
putfn(filename,attrib)
char *filename; int *attrib;
/* called by getfirst & getnext, unpacks file name from buf into filename
and sets attrib to file attribute */
{
int n;
char *p;
int *pa;
pa = (int *)(buf+21);
*attrib = *pa;
p = (char *) (buf+30);
n = 12;
filename = cpycnt(p,filename,&n);
}
getfirst(filespec,inattrib,filename,outattrib)
/* search for file matching 'filespec' and having attributes 'attrib'.
returns 0 if no match, else returns <>0 and filename found, also
sets attrib to attributes of file found */
char *filespec, *filename;
int inattrib; int *outattrib;
{
char *p;
int *pa;
buf = malloc(128); /* allocate buffers space */
doscall(0x2F,&inregs,&outregs); /* get current DTA */
temp.dx = outregs.bx; /* save DTA in dx */
inregs.dx = (int) buf;
doscall(0x1A,&inregs,&outregs); /* set DTA to buf */
inregs.dx = (int) filespec; inregs.cx = inattrib;
if (doscall(0x4E,&inregs,&outregs)==0) {
doscall(0x1A,&temp,&outregs); /* reset DTA */
putfn(filename,outattrib);
return(1);
}
else { /* no file */
free(buf);
doscall(0x1A,&temp,&outregs); /* reset DTA */
return(0);
}
}
getnext(filename,attrib)
/* search for next file (assumes previous call to getfirst).
returns 0 if no match, else returns <>0, filename found, and
its attribute */
char *filename; int *attrib;
{
doscall(0x2F,&inregs,&outregs); /* get current DTA */
temp.dx = outregs.bx; /* save DTA in dx */
inregs.dx = (int) buf;
doscall(0x1A,&inregs,&outregs); /* set DTA to buf */
if (doscall(0x4F,&inregs,&outregs)==0) {
putfn(filename,attrib);
doscall(0x1A,&temp,&outregs); /* restore DTA */
return(1);
}
else { /* no file */
free(buf);
doscall(0x1A,&temp,&outregs); /* restore DTA */
return(0);
}
}